
@extends('common.header')

<!-- 1.添加meta csrf_token -->
<meta name="csrf-token" content="{{ csrf_token() }}">  
<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>
<script type="text/javascript">
	
	<!-- 2.设置全局ajax选项 -->
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
	// 获取 token
	var _token = $('meta[name="csrf-token"]').attr('content');
	
	
</script>
<body>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>



<!-- 页面标记  -->
<div class="col-xs-12 col-sm-6 col-md-2" style="font-size:23px;color:#D1EEEE;">
	{{ $title or '' }}
</div>
<div class="col-xs-12 col-sm-6 col-md-10" style="margin-bottom:5%;" >
	<!-- 图片展示区域 -->
	@if( isset($pic_info) )
		@forelse ($pic_info as $pic)
		<div class="picShow" style='width:600px;height:auto;margin-bottom:20px;float:left;'  >
			<div style="float:left;">
				<img style='height:160px;margin-right:3%;border-radius:5px;' src="{{ $pic['pic_url'] }}" />
			</div>
			<!-- 图片 描述 -->
			<textarea name="alt" style='height:80px;width:260px;resize:none;float:left;margin-top:3%;' pid="{{ $pic['id'] }}" class="form-control" >{{ $pic['alt'] or '' }}</textarea>
			
			<div style="width:200px;float:left;margin-top:2%;">
				<label for="face_{{ $pic['id'] }}" style="font-size:22px;cursor:pointer;" >
					@if( $pic['status']==1 )
						<input type='radio' name='face' id="face_{{ $pic['id'] }}" style="cursor:pointer;" value="{{ $pic['id'] }}" checked /> 
					<span style="font-size:15px;" >设为封面</span>
					@else
						<input type='radio' name='face' id="face_{{ $pic['id'] }}" style="cursor:pointer;" value="{{ $pic['id'] }}" /> 
					<span style="font-size:15px;" >设为封面</span>
					@endif
					
				</label>
			</div>
		</div>
		@empty
		@endforelse
	@else
	@endif
	
	
</div>

<div class="col-xs-12 col-sm-6 col-md-12" style="text-align:center;">
	<button  style="width:300px;" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-danger" >确认</button>
</div>	

<div class="col-xs-12 col-sm-6 col-md-12" style="text-align:center;margin-bottom:100px;margin-top:1%;">
	<a href="javascript:history.back();" style="width:300px;" class="btn btn-success">
		返回
	</a>
</div>	


<!-- 1.模态框 不要动 -->
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
	<div class="modal-dialog modal-sm" role="document" id='show_info'  style="margin-top:80px;margin-left:45%;color:white;font-size:20px;">
	</div>
</div>	
	
<div style="mairgin-bottom:80px;" id="news" newsId="{{ $news_id }}" >
</div>
	


<script type="text/javascript">
		
	// 获取 token
	var _token = $('meta[name="csrf-token"]').attr('content');
	$(function(){
		
		// 执行 编辑 属性 资讯
		$("button").click(function(){
			
			// 定义 属性 字符串
			var alt_str	= '';	
			$("textarea[name='alt']").each(function(){
				// 输入的属性
				var val=$(this).val();
				// 图片ID
				var pid=$(this).attr('pid');
				// 按规则 拼接好
				alt_str += pid+':'+val+',';
			});	
			
			
			// 封面信息
			var face = $("input[type='radio']:checked").val();
			
			// 资讯 ID
			var news_id = $("#news").attr('newsId');
			
			$.ajax({
				type:"post",
				url:"{{ url('/news/updalt') }}/"+news_id,
				data:{alt:alt_str,face:face,_token:_token},
				async:true,    						
				dataType:"json",
				success:function(back){
					// 2.模态框 不要动
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					if( back['show_info']=='设置成功' )
					{
						setTimeout(function(){
							location.href="{{ url('/news/index') }}";
						}, 1000);  
						
					}
					
				}
			});
			
			
		});
	});

</script>
</body>
@extends('common.footer')